<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" 
          xmlns:c="http://java.sun.com/jsp/jstl/core"
          version="1.2">
  <jsp:directive.page contentType="text/html;charset=UTF-8" language="java" />
  <jsp:scriptlet>
<![CDATA[
  com.google.appengine.api.users.UserService userService =
    com.google.appengine.api.users.UserServiceFactory.getUserService();

  boolean loggedin = userService.isUserLoggedIn();
  if (userService.isUserLoggedIn()) {   
    response.sendRedirect(userService.createLogoutURL(request.getRequestURI()));
    return;
  }

  String appname = System.getProperty("app.name",
                                      com.google.apphosting.api.ApiProxy.getCurrentEnvironment().getAppId().replaceFirst("^s~", ""));
  // app.name can be specified as a system property in
  // appengine-web.xml, defaults to required appid.
  
  String loginURL = userService.createLoginURL("/index.jsp");
]]>
  </jsp:scriptlet>
  <c:set var="loggedin">
    <jsp:expression>loggedin</jsp:expression>
  </c:set>
  <c:set var="appname">
    <jsp:expression>appname</jsp:expression>
  </c:set>
  <c:set var="loginURL">
    <jsp:expression>loginURL</jsp:expression>
  </c:set>
  <jsp:text>
    <html>
      <head>
        <title> Logout of ${appname} </title>
      </head>
      <body>
        <h3>You are now logged out of ${appname}</h3>
        <p>Logging out of ${appname} has probably logged you out of Google as well</p>
        <p>Thanks for stopping by!</p>
        <p>If you want, you can log back in <a href="${loginURL}">here</a></p>
      </body>
    </html>
  </jsp:text>
</jsp:root>
